package isjinhao.jlox.grammar.statement;

import isjinhao.jlox.grammar.expression.ExpressionParser;
import isjinhao.jlox.grammar.expression.represention.Expression;
import isjinhao.jlox.grammar.expression.represention.Identifier;
import isjinhao.jlox.lexical.TokenSequence;
import isjinhao.jlox.lexical.TokenType;

/**
 * @Author ISJINHAO
 * @Date 2021/2/27 16:26
 */
public class StatementExpressionParser extends ExpressionParser {

    public StatementExpressionParser(TokenSequence tokenSequence) {
        super(tokenSequence);
    }

    /**
     * primary      ->  "nil" | NUMBER | STRING | "true" | "false" | "(" expression ")" | IDENTIFIER
     */
    @Override
    protected Expression primary() {
        if (tokenSequence.curEqual(TokenType.IDENTIFIER)) {
            tokenSequence.advance();
            return new Identifier(tokenSequence.takePre());
        }
        return super.primary();
    }

}
